using UnityEngine;

public class CharacterPart : MonoBehaviour
{
	private float maxHp;

	public float multiplier = 1f;

	public float physicsMultiplier = 1f;

	public float weakness = 1f;

	private CharacterFighting fighting;

	private Rigidbody rig;

	private Vector3 lastVelocity;

	public bool isGun;

	public float gunHp = 1f;

	private float currentGunHp;

	public CharacterPart[] parts;

	private CharacterHealth health;

	[SerializeField]
	private bool isHead;

	private void Start()
	{
		fighting = GetComponentInParent<CharacterFighting>();
		health = GetComponentInParent<CharacterHealth>();
		rig = GetComponent<Rigidbody>();
		rig.maxAngularVelocity = 30f;
	}

	private void OnEnable()
	{
		currentGunHp = gunHp;
	}

	private void LateUpdate()
	{
		lastVelocity = rig.velocity;
	}

	private void OnCollisionEnter(Collision collision)
	{
		if (!health.GetComponent<CharacterInformation>().isAlive)
		{
			return;
		}
		if (collision.gameObject.CompareTag("KillOnTouch"))
		{
			health.TakeDamage(1000f, null, isHeadShot: false);
			Vector3 position = health.GetComponent<CharacterInformation>().mainRig.position;
			Vector3 point = collision.contacts[0].point;
			if (collision.gameObject.name.Equals("Left"))
			{
				health.GetComponent<CharacterParticles>().PlayFalloutEffect(point, new Vector3(180f, 0f, 0f));
			}
			else if (collision.gameObject.name.Equals("Right"))
			{
				health.GetComponent<CharacterParticles>().PlayFalloutEffect(point, new Vector3(0f, 0f, 0f));
			}
			else if (collision.gameObject.name.Equals("Top"))
			{
				health.GetComponent<CharacterParticles>().PlayFalloutEffect(point, new Vector3(90f, 0f, 0f));
			}
			else if (collision.gameObject.name.Equals("Bottom"))
			{
				health.GetComponent<CharacterParticles>().PlayFalloutEffect(point, new Vector3(-90f, 0f, 0f));
			}
		}
		else if (collision.rigidbody != null)
		{
			Weapon component = collision.rigidbody.gameObject.GetComponent<Weapon>();
			if (component != null && !fighting.hasWeapon && !component.owner)
			{
				fighting.PickupWeapon(component, forcePick: false);
			}
		}
	}

	public void TakeDamage(float damage, CharacterInformation info, Vector3 force)
	{
		health.TakeDamage(damage, info, isHead);
		rig.AddForce(force, ForceMode.Impulse);
		health.GetComponent<CharacterParticles>().PlayTakeDamageEffect(base.transform.position, force);
	}
}
